package com.hzm.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hzm.dao.PlayHistoryDao;
import com.hzm.entity.PlayHistory;
import com.hzm.service.PlayHistoryService;
import com.hzm.utils.Result;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @program: qy137-java
 * @description:
 * @author: 皇子明
 * @create: 2021-10-24 21:19
 **/
@RestController
@RequestMapping("/order/play-history")
public class PlayHistoryController {
    @Resource
    private PlayHistoryService playHistoryService;
    @Resource
    private PlayHistoryDao playHistoryDao;
    @PostMapping("/insertPlayHistoryByCourseId/{courseID}/{userId}/{vedeo_id}")
    @ApiOperation(value = "插入或者更新消息(tb_play_history)")
    public Result insertPlayHistoryByCourseId(@PathVariable("courseID") String courseID, @PathVariable("userId") String userId, @PathVariable("vedeo_id") String vedeoId){
        QueryWrapper<PlayHistory> wrapper = new QueryWrapper<>();
        wrapper.eq("user_id",userId);
        wrapper.eq("vedeo_id",vedeoId);
        PlayHistory selectOne = playHistoryDao.selectOne(wrapper);
        Result result =null;
        if (selectOne==null){
           result= playHistoryService.insertPlayHistoryByCourseId(vedeoId,userId);
           result=new Result(2000,"插入成功",result);
        }else {
            result= playHistoryService.updatePlayHistory(userId,vedeoId);
            result=new Result(2000,"更新成功",result);
        }
        return result;
    }
    @PostMapping("/queryPlayHistoryBy/{page}/{limit}/{HuiYuanId}")
    @ApiOperation(value = "查询tb_play_history")
    public Result queryPlayHistoryBy(@PathVariable("page") Integer page,@PathVariable("limit") Integer limit,@PathVariable("HuiYuanId") String HuiYuanId,@RequestBody PlayHistory playHistory){
        Result result = playHistoryService.queryPlayHistory(page,limit,HuiYuanId,playHistory);
        return result;
    }
    @PostMapping("/updatePlayHistory/{userId}/{vedeoId}")
    public Result updatePlayHistory( @PathVariable("userId") String userId,@PathVariable("vedeo_id") String vedeoId){
//            查询
        Result result = playHistoryService.updatePlayHistory( userId,vedeoId);
        return result;
    }
}
